import javafx.scene.input.KeyCode;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

import static javafx.scene.input.KeyCode.H;

public class Hillsorting {
    public static  void main(String[] args) {
        int[] arr=new int[8000000];
        for (int i = 0; i < 8000000; i++) {
            arr[i]=(int) (Math.random()*80000);
        }
        Date date1 = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSSS");
        String s1 = simpleDateFormat.format(date1);
        System.out.println("排序前：" + s1);
        Hillsorting1(arr);
        Date date2 = new Date();
        String s2 = simpleDateFormat.format(date2);
        System.out.println("排序后：" + s2);

      /*  System.out.println(Arrays.toString(arr));
        Hillsorting1(arr);*/
      /*  System.out.println(Arrays.toString(arr));*/

    }
    public static void Hillsorting1(int[] arr){
        for (int i = arr.length/2; i>0; i/=2) {
            for (int j = i; j < arr.length; j++) {
                int k=j;
                int temp=arr[k];
                if (arr[k]<arr[k-i]){
                    while (k-i>=0&&temp<arr[k-i]){
                        arr[k]=arr[k-i];
                        k-=i;
                    }
                    arr[k]=temp;
                }
            }
        }
    }
    public static void Hillsorting(int[] arr){
        for (int i = arr.length/2; i > 0 ; i/=2) {
            for (int j =i ; j < arr.length; j++) {
                for (int k = j-i; k >=0 ; k-=j) {
                    if (arr[k]>arr[k+i]){
                        int temp=arr[k];
                        arr[k]=arr[k+i];
                        arr[k+i]=temp;
                    }
                }
            }
        }
    }
}
